﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyTetris
{
    /// <summary>
    /// 方块工厂：产生随机方块
    /// </summary>
    public class BlockFactory
    {
        private static Random rand = new Random();

        public static BaseBlock Create()
        {
            BaseBlock r = null;
            //用小于5的随机整数选择小方块出现的种类
            int type = rand.Next(5);

            switch(type)
            {
                //当随机数为0的时候，出现T形小方块
                case 0:
                    r = new TBlock();
                    break;
                //当随机数为1的时候，出现Z形小方块
                case 1:
                    r = new ZBlock();
                    break;
                //当随机数为2的时候，出现L形小方块
                case 2:
                    r = new LBlock();
                    break;
                //当随机数为3的时候，出现长条形小方块
                case 3:
                    r = new IBlock();
                    break;
                //当随机数为4的时候，出现正方形小方块
                case 4:
                    r = new OBlock();
                    break;
            }
            return r;
        }
    }
}
